#include "StdAfx.h"
#include "../Engine/TerrainTile.hpp"
#include "../Engine/UnitEntity.hpp"
#include "../Engine/UnitEntityManager.hpp"

namespace he
{
	UnitEntityManager::UnitEntityManager(boost::filesystem::path const &WrkPath, Ogre::SceneManager &SceneManager)
		: m_WrkPath(WrkPath), m_UnitManager(WrkPath), m_SceneManager(SceneManager)
	{
	}

	UnitEntityPtr_t UnitEntityManager::create_afv(std::string const &Side, std::string const &UnitType, TerrainTile const &InitialPosition)
	{
		// Create unit
		UnitPtr_t p_unit = m_UnitManager.load_afv_unit(Side, UnitType);
		// Create entity
		Ogre::Entity *p_entity = m_SceneManager.createEntity(UnitType + ".mesh");
		// Add as child node
//		Ogre::SceneNode *p_node = m_SceneManager.getRootSceneNode()->createChildSceneNode(Ogre::Vector3(*InitialPosition.get_vertex(1)));
		Ogre::SceneNode *p_node = m_SceneManager.getRootSceneNode()->createChildSceneNode(Ogre::Vector3(6.f, 15.f, 24.f));
		p_node->attachObject(p_entity);

		return UnitEntityPtr_t(new UnitEntity(p_unit, p_entity, p_node));
	}
} /*he*/